package com.mec.beans.y2012.ajax;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import org.apache.log4j.Logger;

public class NameService {
	
	private List<String> names;
	
	private NameService(List<String> listOfNames){
		this.names = listOfNames;
	}
	
	public static NameService getInstance(List<String> names){
		return new NameService(names);
	}
	
	public List<String> findNames(String prefix){
		String prefixUpper = prefix.toUpperCase();
		
		//
		List<String> matches = new ArrayList<String>();
		Iterator<String> iter = names.iterator();
		
		while(iter.hasNext()){
			String name = iter.next();
			String nameUpper = name.toUpperCase();
			if(nameUpper.startsWith(prefixUpper)){
				matches.add(name);
			}
		}
		//
		return matches;
	}
	
	private static final Logger logger = 
			Logger.getLogger(NameService.class);

}
